package se.topshelf.golftracker.util;

import se.topshelf.golftracker.core.domain.*;

/**
 * Creates full blown entity instances to be used in tests.
 */
public class ObjectMother {
    public static Continent defaultContinent = createContinent();
    public static Country defaultCountry = createCountry(defaultContinent);
    public static MemberClub defaultMemberClub = createMemberClub();

    public static void reInitialize() {
        defaultContinent = createContinent();
        defaultCountry = createCountry(defaultContinent);
        defaultMemberClub = createMemberClub();
    }

    public static Player createPlayer(MemberClub memberClub, String birthDate, String lastThreeOfGolfId) {
        Address address = createAddress();
        Player player = new Player(GolfId.createGolfId(birthDate, lastThreeOfGolfId), "Magnus", "Almeby", 16.0, address);
        memberClub.addMember(player);
        return player;
    }

    public static MemberClub createMemberClub() {
        return new MemberClub("Test Club", createAddress());
    }

    public static Address createAddress() {
        return new Address("Test street", "666", "66666", "Test City", defaultCountry);
    }

    public static Country getDefaultCountry() {
        return defaultCountry;
    }

    private static Country createCountry(Continent continent) {
        Country country = new Country("SE", "Sweden");
        continent.addCountry(country);
        return country;
    }

    public static Continent getDefaultContinent() {
        return defaultContinent;
    }

    private static Continent createContinent() {
        return new Continent("EU", "Europe");
    }

    public static Hole createHole(Course course) {
        Integer orderOnCourse = 1;
        Integer slopeIndex = 3;
        Integer par = 4;
        Hole hole = new Hole(orderOnCourse, slopeIndex, par);
        String description = "test";
        hole.setDescription(description);
        String name = "The road hole";
        hole.setName(name);
        course.addHole(hole);
        return hole;
    }

    public static TeeBox createTeeBox() {
        return new TeeBox(355, TeeColour.YELLOW);
    }

    public static Shot createShot(Club club) {
        return new Shot(club, 215, ShotDirection.ON_TARGET, ShotLength.SHORT);
    }

    public static Club createClub(ClubModel clubModel) {
        Club club = new Club(clubModel, ClubType.DRIVER);
        clubModel.addClub(club);
        return club;
    }

    public static ClubModel createClubModel() {
        Manufacturer manufacturer = createManufacturer();
        ClubModel d910 = new ClubModel(manufacturer, "D910");
        manufacturer.addClubModel(d910);
        return d910;
    }

    public static Manufacturer createManufacturer() {
        return new Manufacturer("TLT", "Titleist");
    }

    public static Course createCourse() {
        Course course = new Course("Old Course");
        return course;
    }
}
